﻿using UnityEngine;
using System.Collections;

namespace Battle
{
	public class Actor :IEventListener, IBattleObject,ISteeringEntity
    {
		#region implemented abstract members of IEventListener

		public virtual void OnReceiveMsg(EventType type, EventTelegam t)
		{

		}

		public virtual ListenerPriority Priority()
		{
			return ListenerPriority.NORMAL;
		}

		public virtual string ListenerID ()
		{
			return id;
		}

		#endregion

		#region implemented methods of IEventListner

		public virtual void OnInit()
		{
			if(behaviour!=null)
				behaviour.OnInit();
		}
		
		public virtual void OnUpdate(float delta)
		{
			if(behaviour!=null)
				behaviour.OnUpdate(delta);
		}

		#endregion


        #region implemented methods of ISteering

        protected float speed = 0.01f;
        public float Speed
        {
            get { return speed; }
            set { speed = value; }
        }

        protected float maxSpeed = 1f;
        public float MaxSpeed
        {
            get{ return maxSpeed; }
            set{ maxSpeed = value; }  
        }

        protected Vector3 ahead = Vector3.up;
        public Vector3 Ahead
        {
            get { return ahead; }
            set { ahead = value; }
        }
        protected float accelerate;
        public float Accelerate
        {
            get { return accelerate; }
            set { accelerate = value; }
        }
        protected Vector3 position;
        public Vector3 Position
        {
            get { return position; }
            set { position = value; }
        }

        #endregion


		public Actor(string id)
		{
			this.id = id;
		}


		protected string id = string.Empty;
		public string ID{
			get {return id;}
		}

		protected float hp = 100;
        public float Hp
        {
            get { return hp; }
            set { hp = value; }
        }
    	protected float attack;
        public float Attack
        {
            get { return attack; }
            set { attack = value; }
        }
    	protected float defense;
        public float Defense
        {
            get { return defense; }
            set { defense = value; }
        }
    	protected float attackRange;
        public float AttackRange
        {
            get { return attackRange; }
            set { attackRange = value; }
        }
    	protected float detechRange;
        public float DetechRange
        {
            get { return detechRange; }
            set { detechRange = value; }
        }

        protected Actor target;
        public Actor Target
        {
            get { return target; }
            set { target = value; }
        }

        public bool isAttacking = false;

        public bool ApproachingTower{ get; set;}


        private Behaviour behaviour = null;
        public void Bind(Behaviour b)
        {
            behaviour = b;
        }

        public virtual bool InAttackRange(Actor target)
        {
            return false;
        }

        public virtual Actor DetechTarget()
        {
            return null;
        }


        public Behaviour GetBehaviour()
        {
            return behaviour;
        }

        public void SetBehaviour(Behaviour b)
        {
            behaviour = b;
        }
    }
}


